package com.tdkj.service.shop.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.shop.IBeanGoodRequestToBuyDao;
import com.tdkj.model.common.BeanType;
import com.tdkj.model.shop.BeanGoodRequestToBuy;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.BaseService;
import com.tdkj.service.shop.IBeanGoodRequestToBuyService;

@Component
public class BeanGoodRequestToBuyServiceImpl extends BaseService implements
		IBeanGoodRequestToBuyService {
	
	private  IBeanGoodRequestToBuyDao beanGoodRequestToBuyDao;
    
	@Resource
	public void setBeanGoodRequestToBuyDao(IBeanGoodRequestToBuyDao beanGoodRequestToBuyDao) {
		this.beanGoodRequestToBuyDao = beanGoodRequestToBuyDao;
	}

	public IBeanGoodRequestToBuyDao getBeanGoodRequestToBuyDao() {
		return beanGoodRequestToBuyDao;
	}
	

	@Override
	public BeanGoodRequestToBuy add(Long typeId, Long userId, String description) {
		BeanType type =  beanGoodRequestToBuyDao.findById(typeId, BeanType.class);
		BeanUser user =  beanGoodRequestToBuyDao.findById(userId, BeanUser.class);
		
		BeanGoodRequestToBuy bean = new BeanGoodRequestToBuy();
		bean.setDescription(description);
		bean.setType(type);
		bean.setUser(user);
		beanGoodRequestToBuyDao.save(bean);
		
		return bean;
	}

	@Override
	public void update(Long id, Long typeId, Long userId, String description) {
		
		BeanType type =  beanGoodRequestToBuyDao.findById(typeId, BeanType.class);
		BeanUser user =  beanGoodRequestToBuyDao.findById(userId, BeanUser.class);
		
		BeanGoodRequestToBuy bean = beanGoodRequestToBuyDao.findById(id, BeanGoodRequestToBuy.class);
		bean.setDescription(description);
		bean.setType(type);
		bean.setUser(user);
		beanGoodRequestToBuyDao.save(bean);

	}
	
}
